package com.oop.homework08;

/*
现在整理一堆目录下文件名的信息,
"d:/a.png","c:/aaa/a.txt", "d:/aaa/bbb/e.txt",
"c:/c/aa/b.txt", "c:/aaa/g.txt", "c:/aaa/c.png",
"d:/aaa/d.jpg", "d:/ccc/ddd/eee/g.mp3", "d:/nnn/mmm/kkkk/m.txt"
请将这些内容存到集合中, 然后通过遍历集合, 筛选出后缀名是.txt所有信息,
并且打印出文件名信息(注意不要前面文件夹的名字)
例如: "c:/aaa/a.txt"这个路径满足条件则应该输出 a.txt
*/
public class work01 {
    public static void main(String[] args) {
        //定义一个字符串数组存放变量
        String[] filesPath = {"d:/a.png", "c:/aaa/a.txt", "d:/aaa/bbb/e.txt",
                "c:/c/aa/b.txt", "c:/aaa/g.txt", "c:/aaa/c.png",
                "d:/aaa/d.jpg", "d:/ccc/ddd/eee/g.mp3", "d:/nnn/mmm/kkkk/m.txt"};
        //遍历字符串数组
        for (int i = 0; i < filesPath.length; i++) {
            //用contains()方法查找包含，.txt的元素
            if (filesPath[i].contains(".txt")){
                //用split()方法在/处分割字符串放到新数组里面
                String[] resoult=filesPath[i].split("/");
                //打印出数组最后一个以/分割的字符串
                System.out.println(resoult[resoult.length-1]);
            }
        }
    }
}
